home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / charon40.zip / TAGCHG.C < prev    next >
Text File  |  1992-03-26  |  2KB  |  98 lines

  1. /* tagchange.c -- translator for use with Charon
  2.     Copyright (C) 1992 Brad K. Clements, Clarkson University
  3.            All Rights Reserved.
  4.  
  5.  
  6. */
  7.  
  8. #include <ctype.h> 
  9. #include <time.h>
  10. #include <string.h>
  11. #define    STANDALONE    0
  12. #include "callback.h"
  13. #include "tagvalue.h"
  14.  
  15. char    *stackinfo="$STACKSIZE:1024";
  16.  
  17. /* Usage:
  18.  
  19.     set a loadstring as follows:
  20.  
  21.                loadstring "[<tagname> [operation] <value>] ..."
  22.  
  23.  
  24.     where tagname is a valid tag string from tagvalue.h
  25.  
  26.     operation is:
  27.  
  28.                =     sets to value
  29.         |    or's in numeric value
  30.         &    ands's numeric value
  31.         +    increment
  32.         -    decrement
  33.  
  34. */
  35.  
  36. int
  37. main(int argc, char *argv[])
  38. {
  39.     int     rc;
  40.     char        ibuffer[128], *tagname, *tagvalue, *value, *op1;
  41.     enum        Mode { TAG, OP1, VALUE, WORKING } mode;
  42.     unsigned    long    nvalue, opvalue;
  43.  
  44.     mode = TAG;
  45.     for(rc=1; rc < argc; rc++) {
  46.                switch (mode) {
  47.                    int    ok = 1;
  48.  
  49.                case TAG :
  50.                 tagname = argv[rc];
  51.                  mode = OP1;
  52.                 break;
  53.             case OP1 :        /* get operation */
  54.                 op1 = argv[rc];
  55.                  mode = VALUE;
  56.                 break;
  57.             case VALUE :
  58.                        value = argv[rc];
  59.                  mode = WORKING;
  60.             case WORKING :        /* fall through */
  61.                        tagvalue = getenv(tagname);
  62.                 if(tagvalue)
  63.                            nvalue = atol(tagvalue);
  64.                 else {
  65.                            nvalue = 0;
  66.                     fprintf(STDERR,"Unknown TagName %s\n",tagname);
  67.                 }
  68.                 opvalue = atol(value);
  69.  
  70.                 switch (*op1) {
  71.                     case '=' :
  72.                                nvalue = opvalue;
  73.                                break;
  74.                     case '|' :
  75.                                nvalue |= opvalue;
  76.                                break;
  77.                     case '+' :
  78.                                nvalue += opvalue;
  79.                                break;
  80.                     case '&' :
  81.                                nvalue &= opvalue;
  82.                                break;
  83.                     default :
  84.                             fprintf(STDERR,"Unknown Opcode %c\n",*op1);
  85.                          ok = 0;
  86.                  }    /* end switch op */
  87.                 if(ok) {
  88.                     sprintf(ibuffer,"%s=%ld",tagname, nvalue);
  89.                     setenv(ibuffer);
  90.                 }
  91.                 mode = TAG;
  92.             }    /* end switch */
  93.     }    /* end for */
  94.  
  95.           return(RT_CHANGED_TAGS);    /* even if we didn't change the text, don't do banners */
  96. }
  97.  
  98.